<?php
require_once ROOT.'/core/modules/content/class.content.php';
$content=new content_class();
$comment_limit=isset($this->config['content_front_side_comment_size'])?$this->config['content_front_side_comment_size']:10;
$article_limit=5;
$click_article_limit=5;
$best_article_limit=5;


$article_list=array();
$result=$this->db->result("SELECT * FROM ".DB_PREFIX."content_article ORDER BY article_id DESC LIMIT 0,$article_limit");
if($result){
	$week=array('日','一','二','三','四','五','六');
	foreach($result as $row){
		$article_list[$row['article_id']]['id']=$row['article_id'];
		$article_list[$row['article_id']]['title']=$row['article_title'];
		$article_list[$row['article_id']]['description']=$row['article_description'];
		$article_list[$row['article_id']]['content']=substr(strip_tags($row['article_content']),0 ,120) . '...';
		$article_list[$row['article_id']]['image']=$row['article_image'];
		$article_list[$row['article_id']]['click_count']=number_format($row['article_click_count']);
		$article_list[$row['article_id']]['comment_count']=number_format($row['article_comment_count']);
		$article_list[$row['article_id']]['category_name']=$this->db->value(DB_PREFIX."content_category","category_name","category_id=".$row['category_id']);
		$article_list[$row['article_id']]['category_id']=$row['category_id'];
		$article_list[$row['article_id']]['uri']=PATH.HTML_DIR.$content->category_parent_path($row['category_id']).'/'.$row['article_html'].'.html';
		$article_list[$row['article_id']]['time']=date('Y-m-d',$row['article_time']);
	}
}
$comment_list=array();
$result=$this->db->result("SELECT a.*,b.article_id,b.category_id,b.article_html FROM ".DB_PREFIX."content_comment AS a LEFT JOIN ".DB_PREFIX."content_article AS b ON a.article_id=b.article_id WHERE a.comment_is_display=1 ORDER BY a.comment_id DESC LIMIT 0,".$comment_limit);
if($result){
	foreach($result as $row){
		$comment_list[$row['comment_id']]['id']=$row['comment_id'];
		$comment_list[$row['comment_id']]['name']=$row['comment_name'];
		$comment_list[$row['comment_id']]['email']=$row['comment_email'];
		$comment_list[$row['comment_id']]['content']=$row['comment_content'];
		$comment_list[$row['comment_id']]['uri']=PATH.HTML_DIR.$content->category_parent_path($row['category_id']).'/'.$row['article_html'].'.html';
		$comment_list[$row['comment_id']]['time']=date('Y-m-d',$row['comment_time']);
	}
}

function deletetr($str) {
    $str = trim($str);
    $str = ereg_replace("\t","",$str);
    $str = ereg_replace("\r\n","",$str);
    $str = ereg_replace("\r","",$str);
    $str = ereg_replace("\n","",$str);
    $str = ereg_replace("    ","",$str);
    return trim($str);
}

$this->template->in('article_list',$article_list);
$this->template->in('comment_list',$comment_list);
$this->template->in('article_click_list',$content->get_click_article($click_article_limit));
$this->template->in('article_best_list',$content->get_best_article($best_article_limit));
$this->template->in('content_category',$content->get_content_category());
$this->template->in('category',$content->get_category());